package org.sfgeeq.chapter2.service;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.sfgeeq.chapter2.helper.DatabaseHelper;
import org.sfgeeq.chapter2.model.Customer;
import org.sfgeeq.chapter2.util.PropsUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Created by Administrator on 2016/5/13.
 */
public class CustomerService {

    /**
     * 查询列表
     * @param keyword
     * @return
     */
    public List<Customer> getCustomerList(String keyword){
        Connection conn=null;
        String sql="";
        List<Customer> list=new ArrayList<Customer>();
        sql="select * from customer";
        try {
            conn= DatabaseHelper.getConnection();
            PreparedStatement stmt=conn.prepareStatement(sql);
            ResultSet rs=stmt.executeQuery();
            while (rs.next()){
                Customer c=new Customer();
                c.setId(rs.getLong("id"));
                c.setName(rs.getString("name"));
                c.setContact(rs.getString("contact"));
                c.setTelephone(rs.getString("telephone"));
                c.setEmail(rs.getString("email"));
                c.setRemark(rs.getString("remark"));
                list.add(c);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return list;
    }
    /**
     * 查询列表 用DBUtils提供的QueryRunner对象可以面向实体进行查询
     * @param keyword
     * @return
     */
    public List<Customer> getDBUtilsCustomerList(String keyword){
        String sql="";
        List<Customer> list=new ArrayList<Customer>();
        sql="select * from customer";
        list=DatabaseHelper.queryEntityList(Customer.class,sql,null);
        return list;
    }
    /**
     * 查看明细
     * @param id
     * @return
     */
    public Customer getCusetomer(long id){
        return null;
    }

    /**
     * 新增数据
     * @param map
     * @return
     */
    public boolean createCustomer(Map<String,Object> map){
        return false;
    }

    /**
     * 更新数据
     * @param map
     * @param id
     * @return
     */
    public boolean updateCustomer(Map<String ,Object> map,long id){
        return false;
    }
    /**
     * 删除数据
     * @param id
     * @return
     */
    public boolean deleteCustomer(long id){
        return false;
    }
}
